function form2json(selector){
    var arr=$(selector).serializeArray();
    var json={};
    arr.forEach(obj=>{
        json[obj.name]=obj.value;
    });
    return json;
}

$.fn.dialog=function(param){
    if(typeof(param)=='object'){
        let def={
            title:'打开模态框',
            btnName:'确定',
            size:'',
            btnBind:null
        }
        Object.assign(def,param);
        let html=` <div class="modal fade">
                    <div class="modal-dialog ${def.size}">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <h4 class="modal-title">${def.title}</h4>
                            </div>
                            <div class="modal-body">
                                
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                <button type="button" class="btn btn-primary">${def.btnName}</button>
                            </div>
                        </div>
                    </div>
                </div>`;
        var $dom=$(html);
        if(def.btnBind!=null){
            $dom.find("button:last").off("click").on("click", def.btnBind);
        }else {
            console.log($dom.find("button:last"));
            $dom.find("button:last").remove();
        }
        $dom.find(".modal-body").append(this);
        $dom.appendTo("body");
    }else if(typeof(param=='string')){
        if("show"==param){
            this.parents(".modal").modal("show");
        }
        if("hide"==param){
            this.parents(".modal").modal("hide");
        }
    }
}